package com.spzx.product.controller;

import com.spzx.common.core.domain.R;
import com.spzx.common.core.web.controller.BaseController;
import com.spzx.common.core.web.page.TableDataInfo;
import com.spzx.common.security.annotation.InnerAuth;
import com.spzx.product.domain.ProductSku;
import com.spzx.product.dto.ProductInfoDto;
import com.spzx.product.dto.SkuQuery;
import com.spzx.product.service.ProductSkuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.Set;

@RestController
@RequestMapping("/productSku")
public class ProductSkuController extends BaseController {

    @Autowired
    private ProductSkuService productSkuService;

    /**
     * 获取销量前20的商品
     *
     * @return
     */
    @InnerAuth
    @GetMapping(value = "/findProductSkuNo20")
    public R<List<ProductSku>> findProductSkuNo20() {
        return R.ok(productSkuService.findProductSkuNo20());
    }

    /**
     * 根据条件查询商品列表信息
     *
     * @param pageNum
     * @param pageSize
     * @param query
     * @return
     */
    @InnerAuth
    @GetMapping("/skuList/{pageNum}/{pageSize}")
    public R<List<ProductSku>> skuList(@PathVariable("pageNum") Integer pageNum,
                                       @PathVariable("pageSize") Integer pageSize,
                                       SkuQuery query) {
        startPage();
        return R.ok(productSkuService.skuList(query));
    }

    /**
     * 根据skuId查询商品详情信息
     *
     * @param skuId
     * @return
     */
    @InnerAuth
    @GetMapping("/item/{skuId}")
    public R<ProductInfoDto> getProductInfoBySkuId(@PathVariable("skuId") Long skuId) {
        return R.ok(productSkuService.getProductInfoBySkuId(skuId));
    }

    /**
     * 根据skuId查询商品sku信息
     *
     * @param skuId
     * @return
     */
    @InnerAuth
    @GetMapping("/sku/{skuId}")
    public R<ProductSku> getSkuInfoBySkuId(@PathVariable("skuId") Long skuId) {
        return R.ok(productSkuService.getSkuInfoBySkuId(skuId));
    }

    /**
     * 根据skuId集合查询商品sku的价格
     *
     * @param skuIds
     * @return
     */
    @InnerAuth
    @PostMapping("/getSkuPrice")
    public R<Map<Long, BigDecimal>> getSkuPrice(@RequestBody Set<String> skuIds) {
        return R.ok(productSkuService.getSkuPrice(skuIds));
    }
}
